package com.linkhub.oms.dao.mpservice.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.linkhub.oms.dao.mapper.BankCardEntityMapper;
import com.linkhub.oms.dao.mpservice.IBankCardService;
import com.linkhub.oms.entity.BankCardEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 商家银行卡表 服务实现类
 * </p>
 *
 * @author echo
 * @since 2024-05-16
 */
@Service
public class BankCardServiceImpl extends ServiceImpl<BankCardEntityMapper, BankCardEntity> implements IBankCardService {

    @Override
    public List<BankCardEntity> listByUserId(String userId) {

        return lambdaQuery()
                .eq(BankCardEntity::getUserId, userId)
                .list();
    }

    @Override
    public boolean exist(Long id, String cardNumber) {
        return lambdaQuery()
                .ne(Objects.nonNull(id), BankCardEntity::getId, id)
                .eq(BankCardEntity::getCardNumber, cardNumber)
                .exists();

    }

    @Override
    public List<BankCardEntity> listByCardNumber(List<String> cardNumbers) {
        if (CollUtil.isEmpty(cardNumbers)) {
            return Lists.newArrayList();
        }
        return lambdaQuery()
                .in(BankCardEntity::getCardNumber, cardNumbers)
                .list();
    }
}
